﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cat.Helper
{
    class List_helper
    {/// <summary>
    /// 去重复的类，生成指定list里去重复后的内容
    /// </summary>
    /// <param name="Untreated"></param>
    /// <param name="Original"></param>
    /// <returns></returns>
        public List<String> OldUrl_delete(List<String> Untreated ,List<String> Original) {
            List<String> new_list = new List<String>();
            foreach (String line in Untreated) {
                if (!Original.Contains(line)&&!new_list.Contains(line))
                    new_list.Add(line);
            }
            return new_list;
        }
        /// <summary>
        /// 用于处理日志的辅助类，保留最后的指定x个数据
        /// </summary>
        /// <param name="Untreared"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public List<String> Save_ByCount(List<String> Untreared,int count) {
            List<String> List_new = new List<string>();
            int start = 0;
            int end = Untreared.Count();
            foreach (String line in Untreared) {

                if ((end - start) < count) {
                    List_new.Add(line);
                }
            }
            return List_new;
        }




        /// <summary>
        /// 识别文章中是否有需要屏蔽的关键词，没找到是true 找到是false
        /// </summary>
        /// <param name="post_content">文章主体</param>
        /// <param name="all_tags">文章标签</param>
        /// <param name="exclude_keys">需要屏蔽的关键词</param>
        /// <returns></returns>

        public bool exclude_content(List<string> post_content, List<string> exclude_keys)
        {
            foreach (String line in post_content)
            {
             
                foreach (String key in exclude_keys)
                {
                 
                    if (key != "" && line.IndexOf(key) >= 0)
                    {
                        Console.WriteLine("需要屏蔽的关键词" + key);
                        return false;
                    }
                }

            }

            return true;
        }

        /// <summary>
        /// 取得某个关键词的值并且读取到list中
        /// </summary>
        /// <param name="dictionary_name">路径名 如.//xxxx//</param>
        /// <param name="file_name">文件名 如cat.txt</param>
        /// <returns></returns>
        public List<String> get_text_value(String dictionary_name, String file_name)
        {

            List<String> today = new List<String>(Get_all_line(dictionary_name, file_name));
            return today;

        }
        private static List<String> Get_all_line(String dictionary_name, String File_path)
        {
            try
            {
                return new List<String>(System.IO.File.ReadAllLines(dictionary_name + File_path));
            }
            catch (Exception e)
            {
                Console.WriteLine("未找到文件" + e);
                new Helper.File_helper().File_existence(dictionary_name);
                new Helper.File_helper().File_existence(dictionary_name + File_path);
                return new List<string>();
            }

        }
    }
}
